import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '数据概览', icon: 'dashboard' }
      }
    ]
  },

  {
    path: '/HouTaiGuanLi',
    component: Layout,
    redirect: '/HouTaiGuanLi/yonghu',
    name: 'HouTaiGuanLi',
    meta: { title: '后台管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'yonghu',
        name: 'yonghu',
        component: () => import('@/views/HouTaiGuanLi/yongHu.vue'),
        meta: { title: '用户', icon: 'table' }
      },
      {
        path: 'caiDan',
        name: 'caiDan',
        component: () => import('@/views/HouTaiGuanLi/caiDan.vue'),
        meta: { title: '菜单', icon: 'tree' }
      },
      {
        path: 'quanXian',
        name: 'quanXian',
        component: () => import('@/views/HouTaiGuanLi/quanXian.vue'),
        meta: { title: '权限', icon: 'tree' }
      },
      {
        path: 'riZhi',
        name: 'riZhi',
        component: () => import('@/views/HouTaiGuanLi/riZhi.vue'),
        meta: { title: '日志', icon: 'tree' }
      }
    ]
  },

  {
    path: '/QiYeGuanLi',
    component: Layout,
    children: [
      {
        path: 'QiYeGuanLi',
        name: 'QiYeGuanLi',
        component: () => import('@/views/QiYeGuanLi/index.vue'),
        meta: { title: '企业管理', icon: 'form' }
      }
    ]
  },

  {
    path: '/TiKuGuanLi',
    component: Layout,
    redirect: '/TiKuGuanLi/jiChuTiKu',
    name: 'TiKuGuanLi',
    meta: {
      title: '题库管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'jiChuTiKu',
        component: () => import('@/views/TiKuGuanLi/jiChuTiKu.vue'), // Parent router-view
        name: 'jiChuTiKu',
        meta: { title: '基础题库' }
      },
      {
        path: 'jingXuanTiKu',
        component: () => import('@/views/TiKuGuanLi/jingXuanTiKu.vue'),
        name: 'jingXuanTiKu',
        meta: { title: '精选题库' }
      },
      {
        path: 'shiTiLuRu',
        component: () => import('@/views/TiKuGuanLi/shiTiLuRu.vue'),
        name: 'shiTiLuRu',
        meta: { title: '试题录入' }
      },
      {
        path: 'zuTiLieBiao',
        component: () => import('@/views/TiKuGuanLi/zuTiLieBiao.vue'),
        name: 'zuTiLieBiao',
        meta: { title: '组题列表' }
      }
    ]
  },
  {
    path: '/XueKeGuanLi',
    component: Layout,
    redirect: '/XueKeGuanLi/xueKe',
    name: 'XueKeGuanLi',
    meta: {
      title: '学科管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'xueKe',
        component: () => import('@/views/XueKeGuanLi/xueKe'), // Parent router-view
        name: 'xueKe',
        meta: { title: '学科' }
      },
      {
        path: 'muLu',
        component: () => import('@/views/XueKeGuanLi/muLu.vue'),
        name: 'muLu',
        meta: { title: '目录' }
      },
      {
        path: 'biaoQian',
        component: () => import('@/views/XueKeGuanLi/biaoQian.vue'),
        name: 'biaoQian',
        meta: { title: '标签' }
      }
    ]
  },

  {
    path: '/MianShiJiQiao',
    component: Layout,
    children: [
      {
        path: 'MianShiJiQiao',
        name: 'MianShiJiQiao',
        component: () => import('@/views/MianShiJiQiao/index.vue'),
        meta: { title: '面试技巧', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
